<?php
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller {
	//添加
	public function insert() {
		if($_SERVER['REQUEST_METHOD']=="GET"){
			$this->display;
		}else if($_SERVER['REQUEST_METHOD']=="POST"){
		$Form = D('user');
		if ($Form -> create()) {
			$result = $Form -> add();
			if ($result) {
				$this -> success('数据添加成功！');
			} else {
				$this -> error('数据添加错误！');
			}
		} else {
			$this -> error($Form -> getError());
		}
	}
	}
	public function edit($uid){
		$Form = M('user');
		$result = $Form -> find($uid);
		if($result){
			$this->assign("result",$result);
			$this->display();
		}else{
			$this -> error('没有要查找的信息！');
		}
	}
	public function update($uid) {
		$Form = D('user');
		if ($Form -> create()) {
			$result = $Form -> save();
			if ($result) {
				$this -> success('操作成功！');
			} else {
				$this -> error('写入错误！');
			}
		} else {
			$this -> error($Form -> getError());
		}
	}

	//读取
	public function read($id = 0) {
		$Form = M('user');
		// 读取数据
		$data = $Form -> select();
		if ($data) {
			$this -> assign('data', $data);
			// 模板变量赋值
		} else {
			$this -> error('数据错误');
		}
		$this -> display();
	}
	//查询
	public function all_list(){
		$m=M("user");
		$result=$m->select();
		$this->assign("result",$result);
		$this->display();
	}
	//删除
	public function delete($uid) {
		// 实例化User对象
		$Form = D('user');
		$result=$Form -> delete($uid);
		if ($result) {
				$this -> success('删除成功！');
			} else {
				$this -> error('删除错误！');
			}

	}

}
?>